import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;



public class Student {
	
	
	public static void main(String[] args) {
		Student[] staff = new Student[3];
		staff[0] = new Student(4, "Candy", 1, 1);
		staff[1] = new Student(5, "Tom", 1, 1);
		staff[2] = new Student(6, "Jack", 1, 1);

		PrintWriter pw = null;
		BufferedReader br = null;

		try {
			pw = new PrintWriter(new FileWriter("d:\\Students.txt"));
			writeData(staff, pw);
			pw.close();

			br = new BufferedReader(new FileReader("d:\\Students.txt"));
			String line = null;
			while ((line = br.readLine()) != null) {
				System.out.println(line);
			}

		} catch (IOException exception) {
			exception.printStackTrace();
		}
			
	}

	
	private static void writeData(Student[] staff, PrintWriter pw) {
		for (Student student : staff) {
			student.write();
		}

	}
	
	private int id;
	private String name;
	private int age;
	private double grade;

	public Student() {

	}

	public void write() {
		// TODO Auto-generated method stub
		System.out.println(id + "|" + name + "|" + age + "|" + grade);
	}

	public Student(int id, String name, int age, double grade) {
		this.id = id;
		this.setName(name);
		this.setAge(age);
		this.setGrade(grade);
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		if (name.length() > 10) {
			throw new IllegalArgumentException("name's length should <=10 " + name.length());
		}
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		if (age <= 0) {
			throw new IllegalArgumentException("age should >0 " + age);
		}
		this.age = age;
	}

	public double getGrade() {
		return grade;
	}

	public void setGrade(double grade) {
		if (grade < 0 || grade > 100) {
			throw new IllegalArgumentException("grade should be in [0,100] " + grade);
		}
		this.grade = grade;
	}

}
